//
//  TDCarDetailIsCanOrderCell.m
//  TBRentClient
//
//  Created by tonbright on 2018/6/5.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TDCarDetailIsCanOrderCell.h"
#import "YXDateHelpObject.h"

#import "TDDateEnumView.h"
#import "TDPriceEnumView.h"
#import "UIView+ZLExtension.h"
@implementation TDCarDetailIsCanOrderCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    for (UIView *view in _view_dateDay.subviews) {
        if ([view isKindOfClass:[UILabel class]]) {
            UILabel *lbe = (UILabel *)view;
            [self.sevenDateLbeArray addObject:lbe];
        }else if ([view isKindOfClass:[UIImageView class]]) {
            UIImageView *imv = (UIImageView *)view;
            [self.sevenDateImgArray addObject:imv];
        }
    }
    for (UIView *view in _view_priceDay.subviews) {
        if ([view isKindOfClass:[UILabel class]]) {
            UILabel *lbe = (UILabel *)view;
            [self.sevenPriceLbeArray addObject:lbe];
        }
    }
    
    self.sevenDateArray = [[YXDateHelpObject manager] latelySevenDateDay:7];
    self.sevenWeekArray = [[YXDateHelpObject manager] latelySevenWeakDay:7];
    self.sevenOriginDateArray = [[YXDateHelpObject manager] latelyTimeYearMonthDay:7];
    
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    float width = Width / 7.0;
    if (_view_dateDay.subviews.count < 7 && _view_priceDay.subviews.count < 7) {
        for (int i = 0; i < 7; i++) {
            TDDateEnumView *dateEnumView = [TDDateEnumView dateEnumView];
            dateEnumView.frame = CGRectMake(i * width, 0, width, 30);
            dateEnumView.dateStr= [self.sevenOriginDateArray[i] stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
            dateEnumView.lbe_date.text = self.sevenDateArray[i];
            if (i == 0) {
                dateEnumView.lbe_date.text = @"今";
            }
            [_view_dateDay addSubview:dateEnumView];
        }
        
        for (int i = 0; i < 7; i++) {
            TDPriceEnumView *priceEnumView = [TDPriceEnumView priceEnumView];
            priceEnumView.frame = CGRectMake(i * width, 0, width, 30);
            priceEnumView.dateStr = [self.sevenOriginDateArray[i] stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
            [_view_priceDay addSubview:priceEnumView];
        }
    }
}




// MARK: - 醉了 这个网络数据让多写了一天的内容都不止----------单独返回7个不就是十分钟写完了,辣鸡
- (void)setDetailCarModel:(TDCarSourceDetailModel *)detailCarModel {
    _detailCarModel = detailCarModel;
    NSArray *statusArray = detailCarModel.schedulelist;
    
    NSMutableDictionary *allSchedulelistPriceDic = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *allSchedulelistStatusDic = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *allSchedulelistPicStatusDic = [NSMutableDictionary new];
    for (TDCalendaShowModel *showModel in statusArray) {
        [allSchedulelistPriceDic setObject:showModel.price forKey:showModel.workday];
        [allSchedulelistStatusDic setObject:showModel.status forKey:showModel.workday];
        [allSchedulelistPicStatusDic setObject:showModel.pick forKey:showModel.workday];
    }
    self.allSchedulelistPriceDic = allSchedulelistPriceDic;
    self.allSchedulelistStatusDic = allSchedulelistStatusDic;
    self.allSchedulelistPicStatusDic = allSchedulelistPicStatusDic;
    
    
    for (UIView *subView in _view_dateDay.subviews) {
        if ([subView isKindOfClass:[TDDateEnumView class]]) {
            TDDateEnumView *dateEnumView = (TDDateEnumView *)subView;
            NSString *status = self.allSchedulelistStatusDic[dateEnumView.dateStr];
            NSString *pick = self.allSchedulelistPicStatusDic[dateEnumView.dateStr];
        }
    }
    
    for (UIView *subView in _view_priceDay.subviews) {
        if ([subView isKindOfClass:[TDPriceEnumView class]]) {
            TDPriceEnumView *priceEnumView = (TDPriceEnumView *)subView;
            NSString *price = self.allSchedulelistPriceDic[priceEnumView.dateStr];
            priceEnumView.lbe_price.text = price;
            
        }
    }
    
}



- (void)setDefaultStatus:(BOOL)isDefault index:(int)index{
    NSArray *statusArray = _detailCarModel.schedulelist;
    TDCarSourceCalendaShowModel *enumStatusModel = statusArray[index];
    UIImageView *imv_date = self.sevenDateImgArray[index];
    UILabel *lbe_price = self.sevenPriceLbeArray[index];
    UILabel *lbe_date = self.sevenDateLbeArray[index];
    lbe_price.text = [NSString stringWithFormat:@"¥%@",enumStatusModel.price];
    if ([[HelpObject changeNull:enumStatusModel.status] isEqualToString:@"1"]) {
        imv_date.hidden = YES;
    }else {
        imv_date.hidden = NO;
    }
}


- (NSMutableArray *)sevenDateLbeArray {
    if (!_sevenDateLbeArray) {
        _sevenDateLbeArray = [NSMutableArray array];
    }
    return _sevenDateLbeArray;
}

- (NSMutableArray *)sevenDateImgArray {
    if (!_sevenDateImgArray) {
        _sevenDateImgArray = [NSMutableArray array];
    }
    return _sevenDateImgArray;
}

- (NSMutableArray *)sevenWeekLbeArray {
    if (!_sevenWeekLbeArray) {
        _sevenWeekLbeArray = [NSMutableArray array];
    }
    return _sevenWeekLbeArray;
}

- (NSMutableArray *)sevenPriceLbeArray {
    if (!_sevenPriceLbeArray) {
        _sevenPriceLbeArray = [NSMutableArray array];
    }
    return _sevenPriceLbeArray;
}

@end
